<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>

    </style>
</head>

<body>
    <!-- ## 1.实现全选，不选，反选
    `num.checked = true选中   num.checked = false不选` -->
    <button>全选</button>
    <button>全不选</button>
    <button>反选</button>
    <br>
    <input type="checkbox" name="" id="" checked>
    <input type="checkbox" name="" id="">
    <input type="checkbox" name="" id="">
    <input type="checkbox" name="" id="">
    <input type="checkbox" name="" id="">
    <input type="checkbox" name="" id="">
    <input type="checkbox" name="" id="">
    <input type="checkbox" name="" id="">

    <script>
        var btn = document.getElementsByTagName('button')
        var checkbox = document.getElementsByTagName('input')

        btn[0].onclick = function () {
            for (var i = 0; i < checkbox.length; i++) {
                checkbox[i].checked = true;
            }
        }

        btn[1].onclick = function () {
            for (var i = 0; i < checkbox.length; i++) {
                checkbox[i].checked = false;
            }
        }

        btn[2].onclick = function () {
            for (var i = 0; i < checkbox.length; i++) {
                /*   if (checkbox[i].checked == true) {
                      checkbox[i].checked = false
                  } else {
                      checkbox[i].checked = true
                  } */
                checkbox[i].checked = !checkbox[i].checked
            }
        }
    </script>
</body>

</html>